/*
 *  SessionDataContainer.java
 * 
 *  Created on May 12, 2008, 10:22:41 PM
 */

package pl.edu.agh.ssm.monitor.data;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;

/**
 * Is this class needed...?
 * @author aneezka
 */
public class SessionDataContainer<T extends SessionData> {

    public void addObserver(SessionDataObserver<T> observer) {
        observers.add(observer);
    }
    
    public void removeObserver(SessionDataObserver<T> observer) {
        observers.remove(observer);
    }
    
    public void add(T t) {
        data.put(t.getId(), t);
        for (SessionDataObserver<T> o : observers) {
            o.fireDataAdded(t);
        }
    }
    
    public void remove(T t) {
        data.remove(t.getId());
        for (SessionDataObserver<T> o : observers) {
            o.fireDataRemoved(t);
        }
    }
    
    public void update(T t) {
        data.put(t.getId(), t);
        for (SessionDataObserver<T> o : observers) {
            o.fireDataUpdated(t);
        }
    }
    
    public boolean contains(T t) {
        return data.containsKey(t.getId());
    }
    
    public T get(String id) {
        return data.get(id);
    }
    
    public List<T> getAll() {
        return new LinkedList<T>(data.values());
    }
    
    private HashMap<String, T> data = new HashMap<String, T>();
    private List<SessionDataObserver<T>> observers = new LinkedList<SessionDataObserver<T>>();
}
